package javaweb.test;

import com.google.gson.Gson;
import javaweb.servlet.impl.BaseServlet;
import org.junit.Test;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author shkstart
 * @creat -08-12 11:27
 */
public class JavaAjaxServlet extends BaseServlet {

    public  void JSAjax(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       response.setContentType("application/json:charset=UTF-8");
       response.setCharacterEncoding("UTF-8");
        Person person = new Person("大海", 45);
        Gson gson = new Gson();
        String s = gson.toJson(person);
        response.getWriter().write(s);
    }
@Test
    public void  test01(){
    Person p1 = new Person();
    p1.setAge(23);
    p1.setName("qwe");
    Gson gson = new Gson();
    String s = gson.toJson(p1);
    System.out.println(s);


}
}
